import Gobj from "./Gobj";
import Gstatic from "./Gstatic";
import GUniverse from "./GUniverse";
import GEnemy from "./GEnemy";
import GBullet from "./GBullet";

export default class GTower extends Gobj{
    constructor(){
        super();
        this.type = Gobj.GTower;
        this.x = Gstatic.xlen / 2;
        this.y = Gstatic.ylen / 2;
        this.v0 = 1;
    }

    copy():Gobj{
        var o = new GTower();
        o.syncTime(this);
        o.id = this.id;
        return o;
    }

    get lv(){
        return this.v0;
    }

    set lv(lv_:number){
        this.v0 = lv_;
    }

    get cd(){
        return this.v1;
    }

    set cd(cd_:number){
        this.v1 = cd_;
    }

    

    timeline(sf:number , lf:number , fms:number , keyf:boolean , u:GUniverse, ac:any){
        this.ct = fms;
        if (this.cd < this.ct ) { 
            this.cd = this.ct + 1000;
            //发射子弹
            var player = u.gm.getPlayer(this.pid);
            var e = player.monsterMap.objArr[0] as GEnemy;
            if(e && !e.die){
                var b:GBullet = new GBullet();
                b.st = fms;
                b.id = u.gm.count++;
                u.gm.count++;
                
                b.uid = e.uid;

                
                b.x = Math.floor( this.x / 100 );// + Gstatic.bposMap[0][0].x;
                b.y = Math.floor( this.y / 100 );// - Gstatic.bposMap[0][0].y;

                b.tx = Math.floor( e.x / 100 );
                b.ty = Math.floor( e.y / 100 );
                b.eid = e.id;
                b.pid = player.pid;                
                player.bulletMap.addObj(b);
                //console.log(" create bullet ");
                
            }
        }
    }
}